package operation;

import book.Book;
import book.bookList;

import java.util.Scanner;

public class Addoperation implements Listoperation{
    @Override
    public void work(bookList booklist) {
        System.out.println("增添图书...");
        Scanner sc=new Scanner(System.in);
        if(booklist.getBooks().length==booklist.getUsesize()){
            System.out.println("书架已满，放不下了");
            return ;
        }
        System.out.println("请输入书名：");
        String name=sc.nextLine();
        for (int i = 0; i < booklist.getUsesize(); i++) {
            if(name.equals(booklist.getBooks(i).getName())){
                System.out.println("书架上已经有这本书");
                return ;
            }
        }
        System.out.println("请输入作者的名字：");
        String author=sc.nextLine();
        System.out.println("请输入该小说的类型：");
        String type=sc.nextLine();
        System.out.println("请输入该书的价格：");
        int price= sc.nextInt();
        Book newbook=new Book(name,author,price,type);
        booklist.setBooks(booklist.getUsesize(),newbook);
        booklist.setUsesize(booklist.getUsesize()+1);
        System.out.println("插入成功");
        return ;
    }
}
